import { _decorator, instantiate, Label, easing, Tween, assetManager, Camera, Node, Color, math, Sprite, SystemEvent, LabelComponent, SkinnedMeshRenderer, Prefab, v3, Vec3, SkeletalAnimation, ProgressBar, tween } from 'cc';

import BaseView from '../../Script/game/BaseView';
import Tool from '../../Script/tool/Tool'
// import { luckyBox } from './luckyBox';
import GD from '../../Script/config/GD';
import GDef from '../../Script/config/GDef';
const { bits } = math;
const { ccclass, property } = _decorator;

@ccclass('preYiLong')
export class preYiLong extends BaseView {
    @property({
        type: Node
    })
    nodeBaoXiang: Node = null;
    onLoad() {
        let self = this;
        assetManager.loadBundle(GDef.pack2, function (err, bundle) {
            if (err) {
                console.error('pack2分包加载失败');
            }
            bundle.load(GDef.preAd, Prefab, function (err, item) {
                if (err) {
                    console.error(err);
                }
                if (!GDef.nodeAd) GDef.nodeAd = instantiate(item);
                GDef.nodeAd.parent = GDef.getRoot();
                GDef.nodeAd.active = true;
                Tool.setPos(GDef.nodeAd, self.nodeBaoXiang, v3(0, 0, 0), v3(1, 1, 1));
            });
        });
        this.tween = tween(this.node).set({ position: v3(-2, 2, 2.6) }).call(() => {
            self.node.setRotationFromEuler(v3(-15, 60, 0));
        }).to(10, { position: v3(2, 2, 2.6) }).call(() => {
            self.node.setRotationFromEuler(v3(-15, 290, 0));
        }).to(10, { position: v3(-2, 2, 2.6) }).union().repeatForever();
    }
    show() {
        if (this.tween) this.tween.stop();
        if (GDef.nodeAd) GDef.nodeAd.active = true;
        this.tween.start();
    }
    update() {
        Tool.setPos(GDef.nodeAd, this.nodeBaoXiang, v3(0, 0, 0), v3(1, 1, 1));
    }
    onDisable() {
        if (this.tween) this.tween.stop();
        if (GDef.nodeAd) GDef.nodeAd.active = false;
    }
}
